package edu.uestc.gene.scripts.combination.entity;

import java.util.ArrayList;
import java.util.List;

import edu.uestc.gene.entity.AdverseDrugReaction;
import edu.uestc.gene.entity.Gene;

/**
 * @author Carl
 * 
 *         2013-10-30
 */
public class Frequencies {

	private AdverseDrugReaction adr;

	private List<Gene> group;

	public Frequencies() {
		group = new ArrayList<Gene>();
	}

	/**
	 * 判断给定基因是否存在于该ADR对应的基因组里
	 * 
	 * @return
	 */
	public boolean isExist(Gene gene) {
		for (int i = 0; i < group.size(); i++) {
			if (group.get(i).equals(gene)) {
				return true;
			}
		}
		return false;
	}

	public int[] index(List<Gene> genes) {
		List<Integer> indexes = new ArrayList<Integer>();
		for (int i = 0; i < genes.size(); i++) {
			for (int j = 0; j < group.size(); j++) {
				if (genes.get(i).equals(group.get(j))) {
					indexes.add(i);
					break;
				}
			}
		}
		int[] results = new int[indexes.size()];
		for (int i = 0; i < results.length; i++) {
			results[i] = indexes.get(i);
		}
		return results;
	}

	public void addGene(Gene gene) {
		if (!isExist(gene)) {
			group.add(gene);
		}
	}

	public void addGenes(List<Gene> genes) {
		for (int i = 0; i < genes.size(); i++) {
			addGene(genes.get(i));
		}
	}

	public AdverseDrugReaction getAdr() {
		return adr;
	}

	public void setAdr(AdverseDrugReaction adr) {
		this.adr = adr;
	}

	public List<Gene> getGroup() {
		return group;
	}

	public void setGroup(List<Gene> group) {
		this.group = group;
	}

}
